package com.example.tests;

import static org.hamcrest.Matchers.*;
import static org.hamcrest.MatcherAssert.*;

import java.util.Random;

import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import com.example.obj.FolderList;

public class Test_02_FolderRemoval extends TestBase{
	
	Random rnd = new Random();
		
	@BeforeMethod
	public void init(){
		if (manager.getFolderHelper().getFolders().size() == 0) {
			log.info("Before: Start folder removal");
			log.info("There are no folders for removal. Try to create one");
			manager.getFolderHelper().createFolder("FolderName");
		}
	}
	
	@Test(priority = 2)
	public void testFolderCanBeDeleted() throws Exception {
		log.info("Start testFolderCanBeDeleted");
		FolderList oldFolderList = manager.getFolderHelper().getFolders();		
		assertThat(oldFolderList.size() > 0, is(true));
		log.info("Old folder list: " + oldFolderList);
		int i = rnd.nextInt(oldFolderList.size());
		String folder = oldFolderList.get(i);
		assertThat(manager.getFolderHelper().deleteFolder(i), is(nullValue()));
		FolderList newFolderList = manager.getFolderHelper().getFolders();
		log.info("New folder list: " + newFolderList);
		log.info("Start assertions: size, lists' elements");
		assertThat(newFolderList.size(), equalTo(oldFolderList.size() - 1));
		assertThat(newFolderList, equalTo(oldFolderList.without(folder)));
	}
}
